﻿/// <reference path="../../../Common/EasyUI/jquery-1.10.2.min.js" />
/// <reference path="../../../Common/EasyUI/jquery.easyui.min.js" />

//实现布局
$(document.body).layout();
//文档加载完毕之后触发的事件
$(document).ready(function () {
    loadModules();
    createMainTabCtrl();
});

function createMainTabCtrl() {
    /// <summary>创建主页面框架的tab控件</summary>
    $("#div_main").tabs({
        fit: true
    });
};

function loadDestop() {
    /// <summary>加载我的桌面页面</summary>
};

function loadModules() {
    /// <summary>加载模块数据</summary>
    $('#ul_modules').tree({
        data: getLeftMenuItems(),
        onClick: function (node) {
            callMenuBtnFun(node.clickFunction);
        }
    });
};

function getLeftMenuItems() {
    /// <summary>获取左边菜单栏</summary>
    //[{ "ID": 2, "ParentID": 0, "Title": "个人设置", "ClickFunction": "", "PowerCode": 0, "OrderIndex": -1, "Status": 1, "IconUrl": "", "ChildModules": [{ "ID": 3, "ParentID": 2, "Title": "密码安全", "ClickFunction": "", "PowerCode": 0, "OrderIndex": -1, "Status": 1, "IconUrl": "", "ChildModules": []}] }, { "ID": 4, "ParentID": 0, "Title": "系统设置", "ClickFunction": "", "PowerCode": 0, "OrderIndex": -1, "Status": 1, "IconUrl": "", "ChildModules": []}]
    var aNewMenus = new Array();
    var sLeftMenuJSON = MyRemoteCall.execBLLFunctionSync("ModuleHelper.GetCurUserCanAccessModulesJSON");
    if (sLeftMenuJSON) {
        var aMenus = $.parseJSON(sLeftMenuJSON);
        for (var i = 0; i < aMenus.length; i++) {
            var aChildMenus = aMenus[i].ChildModules;
            var aChildMenuBtns = new Array();
            if (aChildMenus && aChildMenus.length > 0) {
                for (var j = 0; j < aChildMenus.length; j++) {
                    aChildMenuBtns.push({
                        id: aChildMenus[j].ID,
                        clickFunction: aChildMenus[j].ClickFunction,
                        icon: MyWebsite.parseToUrl(aChildMenus[j].IconUrl),
                        state: 'open',
                        text: aChildMenus[j].Title
                    });
                }
            }
            aNewMenus.push({
                id: aMenus[i].ID,
                state: 'open',
                text: aMenus[i].Title,
                icon: MyWebsite.parseToUrl(aMenus[i].IconUrl),
                children: aChildMenuBtns
            });
        }
    }
    return aNewMenus;
};

function callMenuBtnFun(sParams) {
    /// <summary>模块按钮的单击事件</summary>
    /// <param name="sParams" type="String">按钮的单击参数</param>
    if (sParams) {
        var oParam = $.parseJSON(sParams);
        if (oParam.url) {
            $.loadJs(MyWebsite.parseToUrl(oParam.url), function (inputParam) {
                if (inputParam.func) {
                    eval(inputParam.func);
                }
            }, oParam);
        }
        else if (oParam.func) {
            eval(oParam.func);
        }
    }
};
